package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.AdminRoleService;
import com.cskaoyan.market.db.admin.vo.RoleVo;
import com.cskaoyan.market.db.domain.MarketRole;
import com.cskaoyan.market.db.domain.MarketRoleExample;
import com.cskaoyan.market.db.mapper.MarketRoleMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 小焦
 * @since 2023/03/18 21:02
 */
public class AdminRoleServiceImpl implements AdminRoleService {
	@Override
	public List<RoleVo> options() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		MarketRoleMapper roleMapper = sqlSession.getMapper(MarketRoleMapper.class);
		List<MarketRole> marketRoles = roleMapper.selectByExample(new MarketRoleExample());
		sqlSession.commit();
		sqlSession.close();
		List<RoleVo> roleVoList = new ArrayList<>();
		for (MarketRole marketRole : marketRoles) {
			RoleVo roleVo = new RoleVo();
			roleVo.setValue(marketRole.getId());
			roleVo.setLabel(marketRole.getName());
			roleVoList.add(roleVo);
		}
		return roleVoList;
	}
}
